#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <signal.h>
#include <errno.h>

static void sig_usr(int);	/* one handler for both signals */

int main(void)
{
	pid_t pid;
	pid = fork();
	if (pid < 0){
		perror("Failed in calling fork");
		exit(1);
	}else if(pid == 0){			//Child
		printf("Child 1 created.\n");
		if (signal(SIGINT, sig_usr) == SIG_ERR)
    {
        printf("can't catch SIGINT\n");
        exit(1);
    }
    
    for ( ; ; )
        pause();
	}else{						//Parent
		printf("Child 1 PID: %ld\n", (long)pid);
		if (signal(SIGINT, sig_usr) == SIG_ERR)
    {
        printf("can't catch SIGINT\n");
        exit(1);
    }
    
    for ( ; ; )
        pause();
	}
	
    
}

static void sig_usr(int signo)		/* argument is signal number */
{
    if (signo == SIGINT)
        printf("received SIGUSR1\n");
    else
    {
        printf("received signal %d\n", signo);
        exit(1);
    }
}
